package ssw.game;

import java.util.SortedSet;
import java.util.TreeSet;

public class GameResults {
	private final SortedSet<String> correct;
	private final SortedSet<String> missed;
	private final SortedSet<String> wrong;
	
	public SortedSet<String> getCorrect() {
		return correct;
	}

	public SortedSet<String> getMissed() {
		return missed;
	}

	public SortedSet<String> getWrong() {
		return wrong;
	}

	private GameResults(SortedSet<String> correct, SortedSet<String> missed, SortedSet<String> wrong)  {
		super();
		this.correct = correct; 
		this.missed = missed; 
		this.wrong = wrong; 
	}

	public static GameResults of(GameState state, SortedSet<String> guesses) {
		SortedSet<String> c = new TreeSet<String>(guesses);
		c.retainAll(state.getAnswers());

		SortedSet<String> m = new TreeSet<String>(state.getAnswers());
		m.removeAll(guesses);

		SortedSet<String> w = new TreeSet<String>(guesses);
		w.removeAll(state.getAnswers());
		
		return new GameResults(c, m, w);
	}
	
	@Override
	public String toString()  {
		if (getMissed().isEmpty() && getWrong().isEmpty())  {
			return "You got them all!";
		}
		return "Missed: " + getMissed() + "\nWrong: " + getWrong() + "\nCorrect: " + getCorrect();
	}
}
